<?php
//店铺设置
namespace Store\Controller;
//use Think\Controller;
use Store\Controller\StoreController;
class SetController extends StoreController {

    function _initialize() {
        parent::_initialize();
        $this->assign('sys','set');// 数据集

    }

    public function index(){
        $this->assign('action','coupon');// 页码
        $set = M('store');
        $where['store_id'] = session('store_id');

        if(IS_POST){
            $date['store_name'] = I('store_name');
            $date['background_color'] = I('background_color');
            $date['store_zy'] = I('store_zy');
            $date['store_label'] = I('store_label');
            $date['store_banner'] = I('store_banner');
            $date['store_banner_tel'] = I('store_banner_tel');
            $date['store_qq'] = I('store_qq');
            $date['store_ww'] = I('store_ww');
            $date['store_phone'] = I('store_phone');
            $date['store_keywords'] = I('store_keywords');
            $date['store_description'] = I('store_description');
            $re = $set->where($where)->save($date);
            if($re){
                $this->success('信息修改成功！');
            }else{
                $this->error('信息修改失败！');
            }
        }
        $store = $set->where($where)->find();
        $this->assign('store',$store);
        $this->assign('action','index');
        $this->display();
    }
    
    
    //店铺E幻灯片
    public function slide(){
        $set = M('store');
        $where['store_id'] = session('store_id');
        
        if(IS_POST){
            $img = array();
            $url = array();
            $aa = I('post.');

            asort($aa['store_slide_order']);
            foreach ($aa['store_slide_order'] as $key => $value) {
                $img[] = $aa['store_slide'][$key];

                $url[] = $aa['store_slide_url'][$key];
            }
            //幻灯片图片地址拆分成数组序列化后存入

            $data['store_slide'] = serialize($img);
            //幻灯片对应的链接序列化后存入
            $data['store_slide_url'] = serialize($url);

            $re = $set->where($where)->data($data)->save();
            if($re){
                $this->success('保存成功');
            }else{
                $this->error('失败请稍后重试');
            }
        }
        $store = $set->field('store_slide,store_slide_url')->where($where)->find();
        $slideImg = unserialize($store['store_slide']);
        $slideUrl = unserialize($store['store_slide_url']);
        $this->assign('slideImg',$slideImg);
        $this->assign('slideUrl',$slideUrl);
        $this->assign('action','slide');
        $this->display();
    }
    
    //店铺信息
    public function infos(){
        $map['user_id'] = session('user_id');
        $infos = M('storeJoinin')->where($map)->find();
        $this->assign('info',$infos);
        $this->assign('action','infos');
        $this->display();
    }
    
    
    //店铺域名
    public function domain(){
        $this->assign('action','domain');
        $this->display();
    }
    
    public function yzdomain(){
        $store_domain = I("param");
        $map['store_domain'] = $store_domain;
        sleep(1);
        if (empty($store_domain)) {
            echo "{ \"info\":\"请输入您要申请的二级域名！\", \"status\":\"n\" }";
        }
        //特殊的域名不能
        $str = array('admin','taodudu','taobao','www','store','home','user','mydomain','mobile');
        
        $re = M('store')->where($map)->getField('store_domain');
        if (!is_null($re)) {
            echo "{ \"info\":\"域名已被注册过！请更换个！\", \"status\":\"n\" }";
        } else {
            echo "{ \"info\":\"可以注册！\", \"status\":\"y\" }";
        }
    }
    
    
}